<?php
session_start();
include_once("../service/productService.php");
include_once("../util/constant.php");
include_once("../util/FTP.php");

$name = $_POST["name"];
$value = $_POST["value"];
$imgPath = $_POST["imgPath"];
$isSuccess = false;

if(isset($imgPath)){
	$disId = createDiscount($name, $imgPath, $value / 100);
	if($disId > 0) {
		$isSuccess = true;
        if(IS_ON_SERVER) FTP::getInstance()->ftpMakeDir(FTP::getInstance()->getServerPath()."discount/".$disId, 0777);
        else mkdir("../image/discount/".$disId, 0777); 
	}
} else {
	if(createDiscount($name, "", $value / 100) > 0) $isSuccess = true;
}

if($isSuccess){
	echo "<script>window.location.href = '../admin/discount-detail.php?action=".INSERT_SUCCESSFULLY."&id=".$disId."';</script>";
}
else{
	echo "<script>window.location.href = '../admin/discount-detail.php?action=".INSERT_FAILED."';</script>";
}

?> 